Component({
  behaviors: ['wx://form-field'],
  externalClasses: ['custom-class','list-class','item-class'],
  properties: {
    value: String,
    showPassword: {
      type: Boolean,
      value: true
    },
    inputType: {
      type: String,
      value: 'number'
    },
    maxLength: {
      type: Number,
      value: 6
    },
  },
  data: {
    password: '',
    passwordBoxNumber: 6,
    isFocus: true
  },
  observers: {
    maxLength(value) {
      this.setData({
        passwordBoxNumber: new Array(value)
      })
    }
  },
  methods: {
    handleItemClick() {
      this.setData({
        isFocus: true
      })
    },

    handleInputChange(e) {
      const { password, maxLength } = this.data

      this.triggerEvent('inputChange', e.detail.value)

      if (password.length > maxLength) {
        this.setData({
          isFocus: false
        })
        return
      }

      this.setData({
        password: e.detail.value,
        value: e.detail.value
      })
    }
  },
})
